package com.myStruts.listener;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.myStruts.bean.XmlBean;
import com.myStruts.util.StrutsConfig;

public class ActionListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		System.out.println("信息：系统已经注销！");
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		ServletContext sc = arg0.getServletContext();
		String xmlPath = sc.getInitParameter("struts-config");
		String tomcatPath = sc.getRealPath("\\");
		try {
			Map<String, XmlBean> xmlMap = StrutsConfig.initXml(tomcatPath + xmlPath);
			sc.setAttribute("struts", xmlMap);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("信息：信息已经加载完毕！");
	}

}
